package com.steven.concurrency.example.publish;

import com.steven.concurrency.annoations.NotThreadSafe;

import java.lang.reflect.Array;
import java.util.Arrays;

/**
 * 此种方法在多线程的情况下在线程一在获取数组对象的引用的时候，线程二可能已经
 * 修改了这个对象的引用读取的数据就是错的
 */
@NotThreadSafe
public class UnsafePublish {

    private String [] states={"a","b","c"};

    public String [] getStates(){
        return states;
    }

    public static void main(String[] args) {
        UnsafePublish unsafePublish = new UnsafePublish();

        String[] states = unsafePublish.getStates();
        states[0]="c";
        System.out.println(Arrays.toString(states));
    }
}
